import elementLibraryManager from "../../ElementLibraryManager";
import {LibraryType} from "../../ElementLibraryTypes";

/**
 * @type {LibraryItem}
 */
let curItem;


const insertElementLibraryItem = {
  /**
   * 校验选中的要素项能否使用插入
   * @param _ 忽略
   * @param item {LibraryItem}
   */
  validate(_, item) {
    curItem = item;
    let bRet = true;
    if ((elementLibraryManager.currentDocumentType === "PartDocument" && item?.libraryType !== LibraryType.SKETCH) ||
      (elementLibraryManager.currentDocumentType === "AssemblyDocument" && item?.libraryType === LibraryType.SKETCH)) {
      bRet = false;
    }
    return bRet;
  },
  /**
   * 检测是否允许插入
   * @return
   */
  execute() {
    if (!curItem) {
      return;
    }
    // 调用知识库提供的插入
    elementLibraryManager.insert(curItem)
  }
}

export default insertElementLibraryItem;